<template>
  <div class="layout_billdetail">
    <!-- 新增提示 -->
    <div class="subWall">为了确保信息无误，请先填写身份信息</div>
    <ul class="list" id="billdetail" v-if="resData.type==1">
      <li>
        姓&emsp;&emsp;名：
        <input type="text" v-model="resData.realname" />
      </li>
      <li>
        身份证号：
        <input @blur="isCardNo()" type="text" v-model="resData.identity" />
      </li>
    </ul>
    <ul class="list" id="billdetail" v-else>
      <li>姓&emsp;&emsp;名：{{resData.realname}}</li>
      <li>身份证号：{{resData.identity}}</li>
      <!-- 
                <li>姓&emsp;&emsp;名：<input type="text" v-model="resData.realname"/> </li>
                <li>身份证号：
                    <input @blur="isCardNo()" type="text" v-model="resData.identity"/> 
                </li> 
      -->
    </ul>
    <!-- 图片上传 -->
    <div>
      <div class="uploadMoudle">
        <p>证件正面：</p>
        <cube-upload
          v-if="resData.identity_img==null"
          style="margin-left: 90px;margin-top: -36px;"
          :action="action"
          :max="1"
          @files-added="filesAddedOrder"
          @file-success="fileSuccessOrder"
          @file-removed="fileRemovedOrder"
        />
        <img
          v-else
          class="imgUpload"
          :src="baseUrl+resData.identity_img"
          alt
          @click="handleView(resData.identity_img)"
        />
      </div>
      <div class="uploadMoudle">
        <p>证件反面：</p>
        <cube-upload
          v-if="resData.identity_back_img==null"
          style="margin-left: 90px;margin-top: -36px;"
          :action="action"
          :max="1"
          @files-added="filesAddedOrder1"
          @file-success="fileSuccessOrder1"
          @file-removed="fileRemovedOrder1"
        />
        <img
          v-else
          class="imgUpload"
          :src="baseUrl+resData.identity_back_img"
          alt
          @click="handleView(resData.identity_back_img)"
        />
      </div>
    </div>
    <Modal title="图片预览" v-model="visible">
      <img :src="imgUrl + imgName" v-if="visible" style="width: 100%" />
    </Modal>
    <div class="div1">
      <div class="div2">
        <button @click="authDeal()">提交</button>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from "mint-ui";
import moment from "moment";
import api from "../../assets/js/api";
export default {
    name: "billdetail",
    data() {
        return {
            baseUrl: "http://mmkappnew.oss-cn-beijing.aliyuncs.com/",
            resData: {
                realname: null,
                identity: null,
                order_sn: null,
                type: null,
                identity_img: "", //图片
                identity_back_img: "", //图片
            },
            imgName: "",
            visible: false,
            //上传组件使用
            action: {
                // 正式服
                target: "https://act.yuepinyuemei.com/api/upload/img",
                data: {
                    dirPath: "order"
                }
            },
        };
    },
    mounted() {
        this.axios.defaults.baseURL = api;
        this.order_sn = location.hash.split(":")[1];
        this.authAdd();
    },
    methods: {
        handleView(name) {
            this.imgName = name;
            this.visible = true;
        },
        //图片上传相关操作
        filesAddedOrder(files) {
            //消费凭证
            let hasIgnore = false;
            const maxSize = 20 * 1024 * 1024; // 20M
            for (let k in files) {
                const file = files[k];
                if (file.size > maxSize) {
                    file.ignore = true;
                    hasIgnore = true;
                }
            }
            hasIgnore &&
                this.$createToast({
                    type: "warn",
                    time: 1000,
                    txt: "图片上传失败，不能大于20M"
                }).show();
        },
        fileSuccessOrder(file) {
            this.resData.identity_img = file.response.data.url;
        },
        //图片上传 手动删除
        fileRemovedOrder(file) {
            let curImg = this.resData.identity_img;
            let removeFileUrl = file.response.data.url;

            if (curImg && removeFileUrl) {
                let picArray = curImg.split("#");
                if (picArray) {
                    console.log("删除前的数组为", picArray);
                    let index = picArray.indexOf(removeFileUrl);
                    picArray.splice(index, 1);
                    console.log("删除后的数组为", picArray);

                    curImg = picArray.join("#");
                    console.log("图片上传地址删除后", curImg);
                    this.resData.identity_img = curImg;
                }
            }
        },
        //图片上传相关操作
        filesAddedOrder1(files) {
            //消费凭证
            let hasIgnore = false;
            const maxSize = 20 * 1024 * 1024; // 20M
            for (let k in files) {
                const file = files[k];
                if (file.size > maxSize) {
                    file.ignore = true;
                    hasIgnore = true;
                }
            }
            hasIgnore &&
                this.$createToast({
                    type: "warn",
                    time: 1000,
                    txt: "图片上传失败，不能大于20M"
                }).show();
        },
        fileSuccessOrder1(file) {
            this.resData.identity_back_img = file.response.data.url;
        },
        //图片上传 手动删除
        fileRemovedOrder1(file) {
            let curImg = this.resData.identity_back_img;
            let removeFileUrl = file.response.data.url;

            if (curImg && removeFileUrl) {
                let picArray = curImg.split("#");
                if (picArray) {
                    console.log("删除前的数组为", picArray);
                    let index = picArray.indexOf(removeFileUrl);
                    picArray.splice(index, 1);
                    console.log("删除后的数组为", picArray);

                    curImg = picArray.join("#");
                    console.log("图片上传地址删除后", curImg);
                    this.resData.identity_back_img = curImg;
                }
            }
        },
        // 身份证验证
        isCardNo(){
            // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
            var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            if (reg.test(this.resData.identity) === false) {
                Toast({
                    message: "身份信息有误",
                    position: "bottom",
                    duration: 2000
                });
                this.resData.identity = null
            }
        },
        // 实名认证相关信息获取
        authAdd() {
            let load = this.loading("加载中");
            load.show();
            this.axios
                .post("/api/butler/auth_add", {
                    order_sn: this.order_sn
                })
                .then(res => {
                    load.hide();
                    if (res.data.code == 200) {
                        this.resData = res.data.data;
                    } else if (res.data.code == 250) {
                        Toast({
                            message: "登录过期，请重新登陆",
                            position: "bottom",
                            duration: 2000
                        });
                        this.$router.push("/login");
                        return false;
                    } else {
                        Toast({
                            message: res.data.msg,
                            position: "bottom",
                            duration: 2000
                        });
                        return false;
                    }
                })
                .catch(error => {
                    load.hide();
                    Toast({
                        message: "请求失败，请稍后重试",
                        position: "bottom",
                        duration: 2000
                    });
                });
        },
        //实名认证提交
        authDeal() {
            console.log(JSON.stringify(this.resData))
            // return false
            if(this.resData.identity==null){
                Toast({
                    message: "身份信息有误",
                    position: "bottom",
                    duration: 2000
                });
                return false
            }
            // console.log(this.resData)
            this.axios
                .post("/api/butler/auth_deal", this.resData)
                .then(res => {
                    if (res.data.code == 200) {
                        this.$router.push(
                            "/billdetail:" + this.resData.order_sn
                        );
                    } else if (res.data.code == 250) {
                        Toast({
                            message: "登录过期，请重新登陆",
                            position: "bottom",
                            duration: 2000
                        });
                        this.$router.push("/login");
                        return false;
                    } else {
                        Toast({
                            message: res.data.msg,
                            position: "bottom",
                            duration: 2000
                        });
                        return false;
                    }
                })
                .catch(error => {
                    load.hide();
                    Toast({
                        message: "请求失败，请稍后重试",
                        position: "bottom",
                        duration: 2000
                    });
                });
        }
    }
};
</script>
<style lang="less" scoped>
.uploadMoudle {
  margin-top: 10px;
  background-color: #fff;
  padding: 13px 15px;
}
.uploadMoudle p {
  font-size: 16px;
  text-align: left;
  margin-bottom: 13px;
}
.div1 {
  position: absolute;
  bottom: 20px;
  width: 100%;
}
.div2 {
  display: flex;
  justify-content: center;
}
.my-shadow {
  position: fixed;
  top: 0px;
  left: 0px;
  opacity: 0.4;
  width: 100%;
  height: 100%;
  background-color: #333333;
  z-index: 100;
}

.my-dialog {
  z-index: 101;
  position: fixed;
  bottom: 0px;
  width: 100%;
  height: auto;
  min-height: 150px;
  background-color: #fff;
  overflow: scroll;
  max-height: 100%;
  .close {
    position: relative;
    height: 40px;
  }
  .box {
    display: flex;
    div {
      line-height: 30px;
      text-align: center;
      // width: 33%;
    }

    .box-1 {
      width: 30%;
    }
    .box-2 {
      width: 25%;
    }
    .box-3 {
      width: 45%;
    }
  }
  .my-top {
    div {
      font-weight: bold;
    }
  }
}

.my-button {
  float: right;
  margin-right: 10px;

  span {
    background-color: #ff94b1;
    color: #fff;
    font-size: 16px;
    line-height: 42px;
    height: 42px;
    margin-top: 3px;
    padding: 2px 5px;
    border-radius: 4px;
  }
}

.shadow-line {
  height: 10px;
  background-color: #cccccc;
  opacity: 0.2;
  clear: both;
}

.layout_billdetail {
  width: 100%;
  height: 100%;
  //padding-left: 15px;
  overflow: auto;
  font-size: 17px;
  color: #666;
  text-align: left;
}
.layout_billdetail .list {
  width: 100%;
  position: relative;
}
.list li {
  padding-left: 15px;
  min-height: 50px;
  line-height: 50px;
  border-bottom: 1px solid rgba(204, 204, 204, 0.3242);
  font-size: 17px;
  font-family: "PingFangSC-Medium";
  font-weight: 500;
  color: rgba(102, 102, 102, 1);
  position: relative;
  .tip {
    color: #ccc;
    margin-top: -25px;
  }
}

.line {
  position: relative;
  .member {
    position: absolute;
    right: 5px;
    top: 1px;

    span {
      background-color: #7d3a3a;
      color: #fff;
      border-radius: 6px;
      padding: 2px 4px;
    }
  }
}
.ivu-icon {
  height: 100%;
  line-height: 50px;
  font-size: 20px;
  float: right;
  margin-right: 15px;
}
span {
  height: 48px;
  line-height: 48px;
}
.noteBox {
  width: 95%;
  height: 120px;
  font-size: 17px;
  color: #888;
  border: 1px solid rgba(204, 204, 204, 0.3242);
  word-wrap: break-word;
  margin-bottom: 30px;
  padding-left: 8px;
}

//额外图片
.img {
  margin-top: 6px;
  p {
    height: 50px;
    line-height: 50px;
  }
}
.gray {
  width: 100%;
  height: 1px;
  margin-top: 10px;
  background: rgba(204, 204, 204, 0.2018);
}
//最多只三张图能
.photo {
  width: 100%;
  height: 110px;
}
.photo li {
  width: 90px;
  height: 90px;
  /* background-color: #d8d8d8; */
  margin-bottom: 10px;
  float: left;
  margin-right: 6px;
}
.photo li img {
  width: 90px;
  height: 90px;
  display: block;
}

// 底部经办人 放到右侧！
.right-line {
  font-size: 14px;
  text-align: right;
  margin-right: 6%;
  margin-bottom: 10px;
}
</style>


<style lang="less">
.ivu-modal-footer,
.ivu-modal-header {
  display: none !important;
}
.share {
  display: block;
  margin: 20px auto;
  font-size: 17px;
  letter-spacing: 1px;
}

.aicon {
  width: 70px;
  height: 30px;
  background-color: #fca3bb;
  border-radius: 0 0 10px 0;
  color: #fff;
  line-height: 30px;
  text-align: center;
}

.jiange {
  width: 110%;
  height: 10px;
  background-color: #f4f4f4;
  margin-left: -15px;
}

.row {
  min-height: 48px;
  line-height: 48px;
  background-color: #fff;
  text-align: left;
  padding-left: 15px;
  border-bottom: 1px solid rgba(204, 204, 204, 0.3242) !important;
  position: relative;
}
.allBox {
  position: relative;
}
.billendImg {
  width: 51px;
  height: 51px;
  position: absolute;
  right: 5px;
  top: 5px;
  z-index: 10;
}
.orderClass {
  position: relative;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.subSqurt {
  width: 41px;
  height: 25px;
  background: rgba(234, 137, 137, 1);
  border-radius: 100px 0px 0px 100px;
  color: #fff;
  padding: 0 0 0 10px;
  font-size: 12px;
  line-height: 25px;
}
.subSqurt.all {
  background-color: #5f9bff;
}
.subSqurt.three {
  background-color: #a2a8fa;
}
.subSqurt.second {
  background-color: #f9a77f;
}
.subSqurt.first {
  background-color: #ff94b1;
}
.subWall {
  height: 34px;
  line-height: 34px;
  background-color: #fff6e0;
  padding: 0 15px;
}
.divs {
  width: 50%;
  float: left;
}
.fw {
  float: left;
  width: 100%;
}
.mt-popup {
  width: 100%;
  height: 100%;
}
.imgUpload {
  width: 80px;
  height: 80px;
  margin-left: 90px;
  margin-top: -36px;
}
</style>

